package com.waiting.java8.feature;


import com.netease.rmi.server.User;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description 流
 * @Author bjweitingting
 * @Date 2018/9/30
 **/
public class StreamTest {

    public static void main(String[] args) {
        List<String> test = new LinkedList<>();
        test.add("今天");
        test.add("是");
        test.add("0930");
        test.stream().forEach(item -> System.out.println(item));
        System.out.println("--------------------");
        test.parallelStream().forEach(item -> System.out.println(item));

        List<User> list2 = initList();
        System.out.println("流的过滤功能");
        // list2.stream().filter((User item) ->item.getAge()>18).


        List<Integer> list3 = new LinkedList<>();
        list3.add(18);
        list3.add(120);
        list3.add(10);
        list3.add(250);
        System.out.println("最小的");
        Stream<Integer> stream = list3.stream();
        Optional<Integer> min = stream.min(Integer::compareTo);
        //如果有数据
        if (min.isPresent()) {
            System.out.println(min.get());
        }
        System.out.println("最大的");
        stream = list3.stream();
        Optional<Integer> max = stream.max(Integer::compareTo);
        if (max.isPresent()) {
            System.out.println(max.get());
        }
        System.out.println("------------filter------------");
        list3.stream().filter(item -> item > 18).forEach(item -> System.out.println(item));

        List<String> testStream=Stream.of("today","is","10/11").collect(Collectors.toList());
    }

    /**
     * 初始化一个实体列表
     *
     * @return
     */
    public static List<User> initList() {
        List<User> test = new LinkedList<>();
        test.add(new User("user1", 18));
        test.add(new User("user2", 20));
        test.add(new User("user3", 22));
        test.add(new User("user4", 24));
        return test;
    }
}
